﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using MediaPortal.Configuration;

namespace Burn4You
{
    public class Burn4YouSettings
    {

        #region Settings

        public string ExeLocCDReader = "";
        public string ExeLocMkisofs = "";
        public string ExeLocFFmpeg = "";
        public string ExeLocDvdAuthor = "";
        /// <summary>
        /// Folder Extension dlls for Burn4You are stored
        /// </summary>
        public string ExtensionsDir = "";
        /// <summary>
        /// The folder the plugin files are stored.
        /// </summary>
        public string Burn4YouDir = "";
        /// <summary>
        /// Location of the xml file that holds the BurnTypes
        /// </summary>
        public string BurnTypesXML = "";
        /// <summary>
        /// Folder for storing temp files during the bruning process
        /// </summary>
        public string WorkingFolder = "";
        /// <summary>
        /// The default format the disk is burnt in. E.G. pal or ntsc.
        /// </summary>
        public string DefaultFormat = "";
        /// <summary>
        /// Folder for storing disk templates.
        /// </summary>
        public string TemplateFolder = "";

        #endregion

        public Burn4YouSettings()
        {
            Load();
        }

        public void Load()
        {
            Burn4YouDir = Config.GetFolder(Config.Dir.Base) + "\\Burn4You";
            ExtensionsDir = Burn4YouDir + "\\Extensions";
            BurnTypesXML = Burn4YouDir + "\\BurnTypes.xml";

            StringDictionary settings = new StringDictionary();

            using (MediaPortal.Profile.Settings xmlsettings = new MediaPortal.Profile.Settings("MediaPortal.xml"))
            {
                string MPDir = Config.GetFolder(Config.Dir.Base);

                ExeLocCDReader = xmlsettings.GetValueAsString("Burn4You", "ExeLocCDReader", Burn4YouDir + "\\bin\\cdrecord.exe");
                ExeLocMkisofs = xmlsettings.GetValueAsString("Burn4You", "ExeLocMkisofs", Burn4YouDir + "\\bin\\mkisofs.exe");
                ExeLocFFmpeg = xmlsettings.GetValueAsString("Burn4You", "ExeLocFFmpeg", Burn4YouDir + "\\bin\\ffmpeg.exe");
                ExeLocDvdAuthor = xmlsettings.GetValueAsString("Burn4You", "ExeLocDvdAuthor", Burn4YouDir + "\\bin\\dvdauthor.exe");
                WorkingFolder = xmlsettings.GetValueAsString("Burn4You", "WorkingFolder", Burn4YouDir + "\\WorkingFolder");
                DefaultFormat = xmlsettings.GetValueAsString("Burn4You", "DefaultFormat", "PAL");
                TemplateFolder = xmlsettings.GetValueAsString("Burn4You", "TemplateFolder", Burn4YouDir + "\\Templates");
            }

        }

        public void Save()
        {
            using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings("MediaPortal.xml"))
            {
                xmlwriter.SetValue("Burn4You", "ExeLocCDReader", ExeLocCDReader.Trim());
                xmlwriter.SetValue("Burn4You", "ExeLocMkisofs", ExeLocCDReader.Trim());
                xmlwriter.SetValue("Burn4You", "ExeLocFFmpeg", ExeLocCDReader.Trim());
                xmlwriter.SetValue("Burn4You", "ExeLocDvdAuthor", ExeLocCDReader.Trim());
                xmlwriter.SetValue("Burn4You", "WorkingFolder", WorkingFolder.Trim());
                xmlwriter.SetValue("Burn4You", "DefaultFormat", DefaultFormat.Trim());
                xmlwriter.SetValue("Burn4You", "TemplateFolder", TemplateFolder.Trim());
            }

        }

        public string MediaFolder
        {
            get { return Config.GetFolder(Config.Dir.Skin) + @"\Media";  }
        }


    }
}
